﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="With_WeakHashMap.cs" company="JDML Consulting Ltd.">
//   Copyright 2011 Photon Project - http://photon.codeplex.com
// </copyright>
// <summary>
//   Defines the With_WeakHashMap type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Photon
{
    using System;
    using Collections;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    public class With_WeakHashMap
    {
        protected WeakHashMap<object, object> SystemUnderTest = new WeakHashMap<object, object>();

        [TestClass]
        public class When_keys_are_collected : With_WeakHashMap
        {
            public object Value = new object();
            public int KeyValue = 1;

            public void Given()
            {
                // box key
                object key = KeyValue;
                SystemUnderTest.Add(key, Value);
                GC.KeepAlive(key);

                // ReSharper disable RedundantAssignment
                key = null;
                // ReSharper restore RedundantAssignment

                GC.Collect();
            }

            [TestMethod]
            public void Should()
            {
                Assert.IsFalse(SystemUnderTest.ContainsKey(1));
            }
        }
    }
}